<?
include ('inc/config.php');

if($_GET['table']) $_SESSION['FF']['table'] = $_GET['table'];
else $_GET['table'] = $_SESSION['FF']['table'];

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/xhtml; charset=iso-8859-1">
<title>Contenuti</title>
<style type="text/css">@import 'css/common.css';</style>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/nicEditor/nicEdit.js"></script>
</head>
<body id="contents">
<script type="text/javascript">FF.contents.loading(true);</script>
<div id="contentsContent">

	<div id="contentHeader">
		<?
		if($_GET['table']) {
			$_TABLE = new table($_GET['table']);
			$_TABLE->checkCrones();
			//$_TABLE->manageSettings($_GET['settings']);	
			$_SESSION['FF']['TABLE'] = $_TABLE->table;
			echo '<script>FF.contents.table = "'.$_TABLE->table.'"</script>';
			$tableTitle = $_CONF->get("TABLE.title", $_TABLE->CONF);
			?>
	
			<? include("inc/toolBar.php"); ?>
		
		<h1><?=(($tableTitle)?$tableTitle:$_TABLE->table)?> <span class="description"><?=$_CONF->get("TABLE>DESCRIPTION.nodeValue", $_TABLE->CONF);?></span></h1>
		
		<div id="tabContainer">
			<?= $_TABLE->getPager(); ?>
			<div class="tabStyle">
				<a href="#" onClick="FF.contents.runFilter(this);">Filtra</a>
			</div>
			<? if (isset($_SESSION['FF']['FILTERS'][$_TABLE->table])) { ?>
				<div class="tabStyle eraseTab">
					<a href="content.php?table=<?=$_TABLE->table?>&action=deleteFilter">Cancella Filtro</a>
				</div>
			<? } ?>
			<div class="tabStyle special1" id="tabDuplicate">
				<a href="#" onClick="FF.contents.duplicateRow(this);">Dupplica dato</a>
			</div>
			<div class="tabStyle special1" id="tabMultipleDelete">
				<a href="#" onClick="FF.contents.multipleDelete(this);">Cancellazione multipla</a>
			</div>
			<?
			if($_SESSION['FF']['pageLogger'] != "" && $_SESSION['FF']['pageLogger'] != null) {
				echo '<div class="tabStyle pageLogger"><a href="#" onclick="this.parentNode.style.display=\'none\';">X</a> '.$_SESSION['FF']['pageLogger'].'</div>';
				$_SESSION['FF']['pageLogger'] = "";
			}
			?>
			<div class="clear" id="tabContainerClearer"><br /></div>
		</div>
	</div>
		
	<div id="contentWrapper">
		<div id="tabContent" class="off"></div>
		<? if($_GET['showMessage']) echo '<div id="messagePanel">' . $_MSG[$_GET['showMessage']] . '</div>'; ?>
		<table cellpadding="4" cellspacing="0" width="100%" class="contentsTable" id="contentsTable">
		
		<?= $_TABLE->getContentHeaders(); ?>
		<?
		$datas = $_DB->query($_TABLE->query);
		
		if(!is_string($datas)) {
			for($i=0; $i<count($datas); $i++) {
				// Entro nella riga
				
				$first = true;
				foreach($_DB->getFields($_TABLE->table) as $name => $type) {
					// Scrivo il dato
					$_FIELD = $_CONF->get("TABLE>FIELDS>FIELD.name=".$name.".node", $_TABLE->CONF);
					if($first === true) {
						$idValue = $datas[$i][$name];
						?>
						<tr id="row_<?=$datas[$i][$name]?>" class="<?=(($i%2==0)?"row1":"row2")?>">
						<td width="15"><input class="rowSelector" type="checkbox" onClick="FF.contents.checkRow(this, this.checked);"><input type="hidden" id="idField" value="<?=$name?>"></td>
						<td width="15"><input type="button" value="EDIT" onClick="window.location='edit.php?action=EDIT&editField=<?=$name?>&editId=<?=$idValue?>'"></td>
						<td width="50"><input type="button" value="DEL" onClick="FF.contents.deleteRow('<?=$idValue?>', '<?=$name?>', '<?=$_TABLE->table?>');"></td>
						<?
						$first = false;
					} 
					if($_TABLE->isFieldVisible($name)) {
						// Faccio vedere il dato	
						$_TABLE->showData($datas[$i][$name], (($_FIELD)?$_FIELD:$name), $idValue);
					}
				}
				echo "</tr>";
			}
		} else {
			echo '<tr><td colspan="'.(count($_DB->getFields($_TABLE->table))+3).'"><strong>Impossibile reperire i dati.</strong> (Query: '.$_TABLE->query.')</td></tr>';
		}
		?>
		</table>
	</div>
	
		
	<? } else { ?>
		
		Clicca nel menu' affianco per selezionare i dati da amministrare.	
	
	<? } ?>
</div>
</body>
</html>
